/**************************************************************************//**
 * @file           fmc.h
 * @version        V1.0
 * $Revision:      1 $
 * $Date:          2017/01/04 $
 * @brief          Main function
 * @Author         Jeffrey Kang
 * @ContactInfo    chkang@esmt.com.tw
 *
 * @note
 *
 * Copyright (C) 1998 Elite Semiconductor Memory Technology Corp.
 * All rights reserved.
 *
 ******************************************************************************/
//#include <stdbool.h>
#include <intrins.h>
#include <REG52.h>
#include "define_rsb.h"
#include "fmc.h"


//========================================================================
// I/O Function
//========================================================================
extern volatile fmc_p fmc;


/**
 * @brief       HAL_FMC_RCMD function
 *
 * @param       None
 *
 * @return      None
 *
 * @details     1. 
 */
#if 0
unsigned char HAL_FMC_RCMD( unsigned int cmd )
{
	unsigned char rdata;
	
	//fmc->isp_con    = 0x02;
	//fmc->isp_len[0] = 0x00;
	//fmc->isp_len[1] = 0x00;
	//fmc->isp_len[2] = 0x00;
	//fmc->isp_len[3] = 0x00;
	fmc->isp_cmd1   = cmd & 0xFF;
	fmc->isp_cmd2   = ( cmd >> 8 ) & 0xFF;
	fmc->isp_cmd3   = ( cmd >> 16 ) & 0xFF;
	fmc->isp_act    = 0x01;
	while( ( fmc->isp_stat & 0x02 ) != 0x02 );
	fmc->isp_stat   = 0x00;
	rdata           = fmc->isp_data[0];
	//fmc->isp_con    = 0x00;
	
	return rdata;
}
#endif


/**
 * @brief       HAL_FMC_RCMD function
 *
 * @param       None
 *
 * @return      None
 *
 * @details     1. 
 */
#if 0
void HAL_FMC_WCMD( unsigned int cmd )
{
	//fmc->isp_con    = 0x02;
	//fmc->isp_len[0] = 0x00;
	//fmc->isp_len[1] = 0x00;
	//fmc->isp_len[2] = 0x00;
	//fmc->isp_len[3] = 0x00;
	fmc->isp_cmd1   = cmd & 0xFF;
	fmc->isp_cmd2   = ( cmd >> 8 ) & 0xFF;
	fmc->isp_cmd3   = ( cmd >> 16 ) & 0xFF;
	fmc->isp_act    = 0x01;
	while( ( fmc->isp_stat & 0x02 ) != 0x02 );
	fmc->isp_stat   = 0x00;
	//fmc->isp_con    = 0x00;
}
#endif


/**
 * @brief       HAL_FMC_RDATA function
 *
 * @param       None
 *
 * @return      None
 *
 * @details     1. 
 */
unsigned char HAL_FMC_RDATA( unsigned int cmd, unsigned int addr )
{
	unsigned char rdata;
	
	//fmc->isp_con     = 0x02;
	//fmc->isp_len[0]  = 0x00;
	//fmc->isp_len[1]  = 0x00;
	//fmc->isp_len[2]  = 0x00;
	//fmc->isp_len[3]  = 0x00;
	fmc->isp_cmd1    = cmd & 0xFF;
	fmc->isp_cmd2    = ( cmd >> 8 ) & 0xFF;
	fmc->isp_cmd3    = ( cmd >> 16 ) & 0xFF;
	fmc->isp_addr[0] = addr & 0xFF;
	fmc->isp_addr[1] = ( addr >> 8 ) & 0xFF;
	fmc->isp_addr[2] = ( addr >> 16 ) & 0xFF;
	fmc->isp_act     = 0x01;
	while( ( fmc->isp_stat & 0x02 ) != 0x02 );
	fmc->isp_stat    = 0x00;
	rdata            = fmc->isp_data[0];
	//fmc->isp_con     = 0x00;
	
	return rdata;
}


/**
 * @brief       HAL_FMC_WDATA function
 *
 * @param       None
 *
 * @return      None
 *
 * @details     1. 
 */
#if 0
void HAL_FMC_WDATA( unsigned int cmd, unsigned int addr, unsigned char wdata )
{
	//fmc->isp_con     = 0x02;
	//fmc->isp_len[0]  = 0x00;
	//fmc->isp_len[1]  = 0x00;
	//fmc->isp_len[2]  = 0x00;
	//fmc->isp_len[3]  = 0x00;
	fmc->isp_cmd1    = cmd & 0xFF;
	fmc->isp_cmd2    = ( cmd >> 8 ) & 0xFF;
	fmc->isp_cmd3    = ( cmd >> 16 ) & 0xFF;
	fmc->isp_addr[0] = addr & 0xFF;
	fmc->isp_addr[1] = ( addr >> 8 ) & 0xFF;
	fmc->isp_addr[2] = ( addr >> 16 ) & 0xFF;
	fmc->isp_data[0] = wdata;
	fmc->isp_act     = 0x01;
	while( ( fmc->isp_stat & 0x02 ) != 0x02 );
	fmc->isp_stat    = 0x00;
	//fmc->isp_con     = 0x00;
}
#endif

